/*
Copyright (C) 2011 Ing. Marek Hubal

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "core.h"
#include "IStopWatch.h"
#include "IBitmap2.h"
#include "IBitStream.h"

// .....................................................................................................................
// Spustenie testu cislo 1
// .....................................................................................................................
void __fastcall Test_1(void) {
	IStopWatch W;
	
	INT32 MaxRunCount = 1;
	INT32 RunCount;

	IBitmap2 Bmp;
	
	INT32 R = 0;

	W.StartMeassure();
	for (RunCount = 0; RunCount < MaxRunCount; RunCount++) {
		R = Bmp.LoadFromBMP("d:\\Projects\\open_source\\research\\BiImages\\test\\test_1.bmp");
		if (R != 0) break;
	}
	W.EndMeassure(RunCount);

	IBitmap2 *Bmp1 = Bmp.Clone();
	Bmp1->SaveToBMP("d:\\Projects\\open_source\\research\\BiImages\\test\\test_1.out.bmp");
	Bmp1->Create(1234, 4321); 
	Bmp1->SaveToBMP("d:\\Projects\\open_source\\research\\BiImages\\test\\test_create.bmp");
	delete Bmp1;
	
	W.PrintResultMessage();
}
// .....................................................................................................................

// .....................................................................................................................
// Spustenie testu cislo 2
// .....................................................................................................................
void __fastcall Test_2(void) {
	IStopWatch W;
	
	INT32 MaxRunCount = 1;
	INT32 RunCount;

	IBitStream B;
	
	INT32 R = 0;

	B.AddBIT(true); B.Rewind();

	W.StartMeassure();
	for (RunCount = 0; RunCount < MaxRunCount; RunCount++) {
		B.Rewind();
		for (INT32 i = 0; i < 100000; i++) {
			B.AddBIT(true);
		}
	}
	W.EndMeassure(RunCount);
	W.PrintResultMessage();

	B.Rewind();
	B.AddBIT(false); B.AddBIT(true); B.AddBYTE(0xa7);
	B.AddWORD(0xa7a7);
	B.AddDWORD(0xa7a7a7a7);
	UINT64 A = 0xa7a7a7a7; A <<= 32; A |= 0xa7a7a7a7; B.AddQWORD(A);
	B.Rewind();
	
	if (B.GetBIT() != false) printf("Err 1.");
	if (B.GetBIT() != true) printf("Err 2.");
	if (B.GetBYTE() != 0xa7) printf("Err 3.");
	if (B.GetWORD() != 0xa7a7) printf("Err 4.");
	if (B.GetDWORD() != 0xa7a7a7a7) printf("Err 5.");
	if (B.GetQWORD() != A) printf("Err 6.");
}
// .....................................................................................................................

// .....................................................................................................................
// Hlavna funkcia aplikacie
// .....................................................................................................................
INT32 main(INT32 pArgc, PCHAR *args) {

	Test_1();
	return 0;
}
// .....................................................................................................................
